const app = getApp()
import qs from "qs";
Page({
  data: {
    ProductList:app.data.productList,
    loading:false,
    shareShow:false,//分享弹窗
  },
  //options(Object)
  onLoad: function(options) {
    app.cache_add(this);
  },
  onReady: function() {
    
  },
  onShow: function() {
      if(app.functions.isEmpty(app.functions.getLocalStorage("user"))){
        this.selectComponent("#logon").into(true);
      }else{
        this.selectComponent("#logon").into(false);
      }
      
      if(app.functions.isEmpty(app.functions.getLocalStorage("iscoupon"))){
        this.selectComponent("#coupon").openTheCouponPopUp();
      }
  },
  onHide: function() {

  },
  onUnload: function() {
    app.cache_off(this);
  },
  onPullDownRefresh: function() {
    
  },
  onReachBottom: function() {
    let that=this;
    that.setData({
      loading:true
    })
    setTimeout(()=>{
      that.setData({
        ProductList:that.data.ProductList.concat(app.data.productList),
        loading:false
      })
    },2000)
  },

  onPageScroll: function(e) {
    let that=this;
    if (e.scrollTop > 200) {
      that.selectComponent("#totop").open();
    } else {
      that.selectComponent("#totop").close();
    }
    // 超出停止视频
    const videoId = app.videoId;
    if(videoId){
      let query = wx.createSelectorQuery();
      let wh = wx.getSystemInfoSync().windowHeight;
      query.select('#productItem' + videoId).boundingClientRect(rect => {
            if (rect.top < -rect.height || rect.bottom > (rect.height+wh)) {
              app.videoId = null;
              app.videoContext[videoId].pause();
            }
      }).exec();
    }
  },
  //item(index,pagePath,text)
  onTabItemTap:function(item) {
    console.info(item);
  },
  OnClick(e){
    console.info(e);
    this.setData({
      shareShow:true
    })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function(){
    let share = {};
      share = {
        title: "岳麓区XXX小区零食店邀请您",
        path: '/pages/index/index?shopid=1&shareid=1',
        imageUrl: '/images/63276e7d2753fb65.png'
      };
    return share;
  },
  // 生成海报
  OnShare(){
    console.info("生成海报!");
    this.selectComponent("#share").ShopShare(1);
  },
  onaddCart(e){
    console.info(e);
    let goods = e.detail.goods;
    let index = e.detail.index;
    this.selectComponent("#suk").getProductsDetail(goods.id,index);
  }
});
  